package com.abiao.shop.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @Description: RedisPoolFactory Redis连接池工厂类
 * @Author: AB
 * @Date: 2021-06-24
 * @Version:v1.0
 */
@Service
public class RedisPoolFactory {

    @Autowired
    private RedisConfig redisConfig;
    /**
     * 生成jedisPool注入到springboot容器中
     * @return
     */
    @Bean
    public JedisPool jedisPoolFactory(){
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxIdle(redisConfig.getPoolMaxIdle());
        poolConfig.setMaxTotal(redisConfig.getPoolMaxTotal());
        poolConfig.setMaxWaitMillis(redisConfig.getPoolMaxWait()* 1000L);
        JedisPool jedisPool = new JedisPool(poolConfig, redisConfig.getHost(),
                redisConfig.getPort(),redisConfig.getTimeOut()*1000);
        return jedisPool;
    }
}
